package listiterator;

/**
 * Created by 5406160@qq.com on LiBoWen 李博闻.
 *
 * @ClassName : ListIteratorDemo
 * @Author : 54061
 * @Date: 2022/2/12 14:10
 */

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

public class ListIteratorDemo {
    public static void main(String[] args) {
        //多态创对象
        List<String> list = new ArrayList<>();
        System.out.println("list = " + list);
        //添加元素
        list.add("张三丰");
        list.add("张翠山");
        list.add("赵敏");
        //列表迭代器
        ListIterator<String> lit = list.listIterator();
        while(lit.hasNext()){
            String name = lit.next();
            System.out.println("name = " + name);
            if (name.equals("张翠山")){
                lit.add("韦一笑");
            }
        }
        System.out.println("list = " + list);
    }
}